package cn.com.codingce.student.servlet;

import cn.com.codingce.student.service.IStudentService;
import cn.com.codingce.student.service.impl.StudentServiceImpl;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class DeleteStudentSelvlet
 */
@WebServlet("/DeleteStudentSelvlet")
public class DeleteStudentServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*
         * 删除
         */
        request.setCharacterEncoding("utf-8");
        /*
         * 接受前端传来的 学号
         */
        int no = Integer.parseInt(request.getParameter("sno"));
        IStudentService service = new StudentServiceImpl();
        boolean result = service.deleteStudentNySno(no);

        response.setContentType("text/html; charset=UTF-8");
        response.setCharacterEncoding("utf-8");
        if (result) {
            //response.getWriter().println("删除成功!" + result);
            /*
             * 删除完重新查询
             */
            response.sendRedirect("querybypage");
        } else {
            response.getWriter().println("删除失败!" + result);
        }

    }


    @Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}
